package com.wzg.ftpstresstool;

import com.wzg.ftpstresstool.config.FileGeneratorProperties;
import com.wzg.ftpstresstool.config.FtpProperties;
import com.wzg.ftpstresstool.service.FileGeneratorService;
import com.wzg.ftpstresstool.service.FileReceiverService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
@EnableConfigurationProperties({FileGeneratorProperties.class, FtpProperties.class})
public class FtpStressToolApplication {

    public static void main(String[] args) {
        // 设置系统属性以确保UTF-8编码
        System.setProperty("file.encoding", "UTF-8");
        System.setProperty("sun.jnu.encoding", "UTF-8");
        
        ConfigurableApplicationContext context = SpringApplication.run(FtpStressToolApplication.class, args);
        
        // 根据配置的模式执行不同的逻辑
        FileGeneratorProperties fileGeneratorProperties = context.getBean(FileGeneratorProperties.class);
        FileGeneratorService fileGeneratorService = context.getBean(FileGeneratorService.class);
        FileReceiverService fileReceiverService = context.getBean(FileReceiverService.class);
        
        if ("sender".equals(fileGeneratorProperties.getMode())) {
            // 发送方模式，执行文件生成和上传
            fileGeneratorService.generateFiles();
        } else if ("receiver".equals(fileGeneratorProperties.getMode())) {
            // 接收方模式，执行文件接收和校验逻辑
            fileReceiverService.receiveFiles();
        } else {
            System.err.println("未知的运行模式: " + fileGeneratorProperties.getMode() + "，请配置为sender或receiver");
        }
    }

}